#include "Precomp.h"
#include "UndoStack.h"

UndoStack::UndoStack(size_t size)
:size(size)
{
}

void UndoStack::addAction(boost::function<void()> &action)
{
	actions.push_back(action);
	if(actions.size()>size)
	{
		actions.pop_front();
	}
}

void UndoStack::undo()
{
	if(actions.size())
	{
		actions.back()();//execute the action
		actions.pop_back();//remove it
	}
}

void UndoStack::clear()
{
	actions.clear();
}